<template>
	<view class="container">
		<!-- #ifdef H5 -->
		<u-navbar bgColor="#0e3a5e" title="" :autoBack="true" :safeAreaInsetTop="true" :placeholder="true"
			leftIconColor="#fff" :titleStyle="data.titleStyle">
			<template #center>
				<view class="u-nav-slot" style="display: flex; color: #fff;" @click="data.searchShow = true">
					<text class="navTitle">{{data.title}}</text><u-icon name="arrow-down-fill" color="#fff"
						size="19"></u-icon>
				</view>
			</template>
			<template #right>
				<view class="u-nav-slot"
					v-if="(data.shakeDownType === 'special' && data.role === '调试' && data.adjustType !== 'unqualified') || (data.role === '品管' && (data.adjustType === 'rectification' || data.adjustType === 'sell_check'))">
					<u-icon name="plus-circle-fill" size="19" color="#fff" @click="openModal('add',null)"></u-icon>
				</view>
			</template>
		</u-navbar>
		<!-- #endif -->
		<u-sticky>
			<!-- #ifdef APP-PLUS -->
			<u-navbar bgColor="#0e3a5e" title="" :autoBack="true" :safeAreaInsetTop="true" :placeholder="true"
				leftIconColor="#fff" :titleStyle="data.titleStyle">
				<template #center>
					<view class="u-nav-slot" style="display: flex; color: #fff;" @click="data.searchShow = true">
						<text class="navTitle">{{data.title}}</text><u-icon name="arrow-down-fill" color="#fff"
							size="19"></u-icon>
					</view>
				</template>
				<template #right>
					<view class="u-nav-slot"
						v-if="(data.shakeDownType === 'special' && data.role === '调试' && data.adjustType !== 'unqualified') || (data.role === '品管' && (data.adjustType === 'rectification' || data.adjustType === 'sell_check'))">
						<u-icon name="plus-circle-fill" size="19" color="#fff" @click="openModal('add',null)"></u-icon>
					</view>
				</template>
			</u-navbar>
			<!-- #endif -->
			<view class="searchBox" v-if="data.shakeDownType === 'normal' || data.adjustType == 'Bom'">
				<u-search :clearabled="true" v-model="data.listQuery.keywords" :animation="true" placeholder="请输入关键字"
					@search="reSearch" @custom="reSearch" @change="reSearch" @clear="reSearch"></u-search>
			</view>
		</u-sticky>

		<mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="pdBox" v-if="data.list.length">
				<view class="special_shake" v-if="data.shakeDownType === 'special'" v-for="(item,index) in data.list"
					:key="item.id">
					<block v-if="data.adjustType == 'Bom'">
							<u-read-more :toggle="true" showHeight="200">
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">Bom层级</text>
									<text class="special_shake_item_r">{{item.bomLevel}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">物料编码</text>
									<text class="special_shake_item_r">{{item.materialCode}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">物料名称</text>
									<text class="special_shake_item_r">{{item.materialName}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">规格型号</text>
									<text class="special_shake_item_r">{{item.specificationAndModel}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">物料属性</text>
									<text class="special_shake_item_r">{{item.materialAttribute}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">Bom版本</text>
									<text class="special_shake_item_r">{{item.bomVersion}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">数据状态</text>
									<text class="special_shake_item_r">{{item.dataStatus}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">单位</text>
									<text class="special_shake_item_r">{{item.unit}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">用量分子</text>
									<text class="special_shake_item_r">{{item.usedNumerator}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">用量分母</text>
									<text class="special_shake_item_r">{{item.usedDenominator}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">标准用量</text>
									<text class="special_shake_item_r">{{item.standardUse}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">子项类型</text>
									<text class="special_shake_item_r">{{item.subItemType}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">实际数量</text>
									<text class="special_shake_item_r">{{item.realityNumber}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">辅助属性</text>
									<text class="special_shake_item_r">{{item.assistAttribute}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">用量类型</text>
									<text class="special_shake_item_r">{{item.useType}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">是否跳层</text>
									<text class="special_shake_item_r">{{item.jumpLevel}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">固定损耗</text>
									<text class="special_shake_item_r">{{item.fixLossRate}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">变动损耗</text>
									<text class="special_shake_item_r">{{item.field_6}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">替代策略</text>
									<text class="special_shake_item_r">{{item.replaceStrategy}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">替代方式</text>
									<text class="special_shake_item_r">{{item.replaceWay}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">替代主料</text>
									<text class="special_shake_item_r">{{item.replaceMainMaterial}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">生效日期</text>
									<text class="special_shake_item_r">{{dayjs(item.startDate).format('YYYY-MM-DD')}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">失效日期</text>
									<text class="special_shake_item_r">{{dayjs(item.endDate).format('YYYY-MM-DD')}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">工艺路线</text>
									<text class="special_shake_item_r">{{item.technologyWay}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">存在联副产品</text>
									<text class="special_shake_item_r">{{item.existsByProduct}}</text>
								</view>
								<view class="special_shake_item">
									<text
										class="special_shake_item_l">工位</text>
									<text class="special_shake_item_r">{{item.localStation}}</text>
								</view>
							</u-read-more>
											
					</block>
					<u-read-more v-else :toggle="true" showHeight="200">
						<view class="special_shake_item_top">
							<text style="font-size: 40rpx; font-weight: bold;">{{item.status}}</text>
							<u-icon name="trash" @click="delData(item, index)"
								v-if="data.role === '调试' && item.status === '草稿'"></u-icon>
						</view>
						<view class="special_shake_item">
							<text
								class="special_shake_item_l">{{data.adjustType == 'sell_check' ? '检查项目' : '问题描述'}}</text>
							<text class="special_shake_item_r">{{item.adjustItem}}</text>
						</view>
						<view class="special_shake_item">
							<text
								class="special_shake_item_l">{{data.adjustType == 'sell_check' ? '检验人' : '反馈人'}}</text>
							<text class="special_shake_item_r">{{item.operatorName}}</text>
						</view>
						<view class="special_shake_item">
							<text
								class="special_shake_item_l">{{data.adjustType == 'sell_check' ? '检查日期' : '反馈日期'}}</text>
							<text class="special_shake_item_r">{{formatDate(item.operatorTime)}}</text>
						</view>
						<view class="special_shake_item">
							<text class="special_shake_item_l">处理工时</text>
							<text class="special_shake_item_r">{{item.attr3}}</text>
						</view>
						<!-- <view class="special_shake_item start" v-if="data.adjustType == 'sell_check'">
							<text class="special_shake_item_l">整改意见</text>
							<u-switch class="switch" v-model="item.adjustResult"
									:activeColor="item.adjustResult !== null? '#00a846' :'#2979ff'" activeValue="0"
									inactiveValue="2" :inactiveColor="item.adjustResult !== null? '#dc362e' : '#ffffff'"
									></u-switch>

						</view> -->
						<view class="special_shake_item" v-show="data.adjustType == 'sell_check'">
							<text class="special_shake_item_l">整改意见</text>
							<!-- <text class="special_shake_item_r">{{item.adjustSuggest || '--'}}</text> -->
							<u--input v-model="item.adjustSuggest" placeholder="请输入整改意见" border="none"></u--input>
						</view>
						<view class="special_shake_item" v-if="data.adjustType == 'sell_check'">
							<text class="special_shake_item_l">整改方案</text>
							<text class="special_shake_item_r">{{item.adjustSolution || '--'}}</text>
						</view>
						<view class="special_shake_item"
							v-if="data.adjustType === 'rectification' || data.adjustType === 'sell_check'">
							<text class="special_shake_item_l">责任班组</text>
							<text class="special_shake_item_r">{{item.attr1}}</text>
						</view>
						<view class="special_shake_item"
							v-if="data.adjustType !== 'rectification' && data.adjustType !== 'sell_check'">
							<view class="special_shake_item_l">
								<view class="">
									工艺判定
								</view>
								<view class="">
									品管判定
								</view>
							</view>
							<view class="special_shake_item_r attr">
								<view>
									<view class="">
										{{item.attr1}}
									</view>
									<view class="">
										{{item.attr2}}
									</view>
								</view>
								<Button style="height: 24px;line-height: 24px;" @click="openModal('check',item)"
									v-if="data.role === '品管'">审核</Button>
							</view>
						</view>
						<view class="special_shake_item" v-if="data.role === '调试'">
							<text class="special_shake_item_l">处理方案</text>
							<text class="special_shake_item_r">{{item.adjustResult}}</text>
						</view>
						<view class="special_shake_item">
							<text class="special_shake_item_l">图片</text>
							<view class="special_shake_item_r">
								<u-upload :fileList="item.keyfiles" @afterRead="afterRead" :name='`${item.id}`'
									:disabled="item.status !== '草稿' && data.adjustType !== 'rectification'"
									@delete="deletePic($event,item)" multiple :previewFullImage="true"></u-upload>
							</view>
						</view>

						<view class="special_shake_item" v-if="data.adjustType == 'sell_check'">
							<u-button type="error" :throttleTime="1000" text="不合格"
								@click="qualified(item,2)"></u-button>
							<u-button type="primary" :throttleTime="1000" text="合格"
								@click="qualified(item,0)"></u-button>
						</view>
						<view class=""
							v-if="data.adjustType=='sell_check' &&item.adjustRecords && item.adjustRecords.length">
							<u-steps :current="item.adjustRecords.length" direction="column" dot>
								<u-steps-item :title="`${item7.operateName}`"
									:desc="`${item7.adjustSuggest?item7.adjustSuggest:''} ${item7.adjustSolution?item7.adjustSolution:''} （${formatDate(item.createdTime)} ）`"
									:key="index7" v-for="(item7,index7) in item.adjustRecords" :current="item7.status">
								</u-steps-item>
							</u-steps>
						</view>
						<view style="display: flex;column-gap:20px; ">
							<u-button type="primary" :throttleTime="1000" text="处理方案" @click="openModal('deal',item)"
								v-if="data.role === '品管' && data.adjustType !== 'rectification' && data.adjustType !== 'sell_check'"></u-button>
							<!-- <u-button type="success" :throttleTime="1000" text="关闭" @click="closeItem(item)"
								v-if="data.role === '品管'"></u-button> -->
							<u-button type="primary" :throttleTime="1000" text="提交" @click="openCheckModal(item)"
								v-if="item.status === '草稿' && data.role === '调试'"></u-button>
							<u-button type="primary" :throttleTime="1000" text="提交" @click="endCheck(item)"
								v-if="item.status === '已审核待处理' && data.role === '调试'"></u-button>
						</view>
					</u-read-more>
					
				</view>

				<view class="shake_item" v-if="data.shakeDownType === 'normal'" v-for="(item,index) in data.list"
					:key="item.id">
					
					<block>
						<view class="shake_top" v-if="item.resultType === 'YN'">
							<text style="width: 80px; color: #fff;"></text>
							<view style="flex: 1;display: flex; justify-content: flex-end;">
								<text style="color:#fff; margin-right:6px;">{{item.ynType.split('-')[1]}}</text>
								<u-switch v-model="item.adjustResult"
									:activeColor="item.adjustResult !== null? '#00a846' :'#2979ff'" activeValue="Y"
									inactiveValue="N" :inactiveColor="item.adjustResult !== null? '#dc362e' : '#ffffff'"
									:disabled="(data.adjustType === 'handover')"
									@change="change($event,item)"></u-switch>
								<text style="color:#fff; margin-left:6px;">{{item.ynType.split('-')[0]}}</text>
							</view>
						</view>
						<view class="shake_top" v-if="item.resultType === 'VAL'">
							<text style="width: 80px; color: #fff;"></text>
							<view style="width: 200px;display: flex; justify-content: flex-end;">
								<u--input border="bottom" v-model="item.adjustResult" placeholder="输入调试结果"
									@blur="saveResult(item)" placeholderStyle="color:#000"></u--input>
								<text style="margin-left: 6px;width: 70px;line-height: 34px;"
									@click="openPicker(item,index)">{{item.unit?filterUnit(item.unit): '选择单位'}}</text>
							</view>
						</view>
						<view class="shake_bottom">
							<view class="shake_bottom_item">
								<text class="shake_bottom_l">部位</text>
								<text class="shake_bottom_r">{{item.adjustPart}}</text>
							</view>
							<view class="shake_bottom_item">
								<text class="shake_bottom_l">检查项目</text>
								<text class="shake_bottom_r">{{item.adjustItem}}</text>
							</view>
							<view class="shake_bottom_item" v-if="item.isExpand">
								<text class="shake_bottom_l">工艺/检验标准</text>
								<text class="shake_bottom_r">{{item.standard}}</text>
							</view>
							<view class="shake_bottom_item" v-if="item.isExpand">
								<text class="shake_bottom_l">检验方法/器具</text>
								<text class="shake_bottom_r">{{item.adjustMethod}}</text>
							</view>
							<view class="shake_bottom_item" v-if="item.isExpand">
								<text class="shake_bottom_l">图片</text>
								<view class="shake_bottom_r">
									<u-upload :fileList="item.keyfiles" @afterRead="afterRead" :name='`${item.id}`'
										:disabled="(data.adjustType === 'handover' || data.adjustType === 'adjust_abnormal')"
										@delete="deletePic($event,item)" multiple :previewFullImage="true"></u-upload>
								</view>
							</view>
							<view class="shake_bottom_item" v-if="item.isExpand">
								<text class="shake_bottom_l">问题描述</text>
								<view class="shake_bottom_r">
									<u--textarea v-model="item.memo" placeholder="请输入内容" @focus="showBtn(item)"
										:disabled="(data.adjustType === 'handover' || data.adjustType === 'adjust_abnormal')"></u--textarea>
								</view>
							</view>
							<view class="" v-if="item.isExpand && item.isBtnShow">
								<u-button type="primary" text="同步整改记录" style="width: 40%;" @click="saveMemo(item)"
									:throttleTime="1000"></u-button>
							</view>
						</view>
						<view class="lookMore" @click="item.isExpand = !item.isExpand">
							<u--image src="../../static/Vector.png" width="46rpx" height="28rpx"></u--image>
						</view>

					</block>


				</view>

				<!-- block -->

			</view>

		</mescroll-body>

		<view class="bottom_img" v-if="data.planStatus === 'PGFH' && data.role === '品管'"
			@click="updatestatus('FHCC','发货出厂', data.planEqmId)">
			<u--image src="../../static/CC.png" width="60px" height="60px"></u--image>
		</view>

		<view class="bottom_img" v-if="data.planStatus === 'WGTS' && data.role === '调试'"
			@click="updatestatus('PGFH','品管复核', data.planEqmId)">
			<u--image src="../../static/FH.png" width="60px" height="60px"></u--image>
		</view>

		<u-picker :show="data.pickerShow" keyName="measureName" :columns="data.pickerColumns"
			@cancel="data.pickerShow = false" @confirm="chooseUnit"></u-picker>

		<u-popup class="projectListPup" mode="left" :show="data.searchShow" :duration="200"
			@close="data.searchShow = false" closeable :safeAreaInsetTop="true">
			<view class="projectList">
				<view class="top" @click="data.searchShow = false">
					<u-icon name="arrow-leftward" size="19" color="#0E3A5E"></u-icon>
					<text class="textBtn">选择类型</text>
				</view>
				<!-- 	<view class="searchPro">
					<u-search :clearabled="true" v-model="searchProjectKey" :actionStyle="{color:'#3D83F1'}"
						:animation="true" placeholder="请输入项目名称" @search="searchPro" @custom="searchPro"
						@change="searchPro" @clear="searchPro"></u-search>
				</view> -->
				<u-cell-group :border="false" class="pcontend" v-if="data.typeList.length">
					<u-cell @click="chooseType(item)"
						:title="`${index+1}丶${item.adjustName}${item.countAll?('（'+(item.countAll - item.countUnHandle+'/'+item.countAll))+'）':''}`"
						:isLink="true" :border="false" v-for="(item,index) in data.typeList" :key="index"
						:class="data.adjustType==item.adjustType?'activePro':''">
						<u-icon slot="right-icon" name="arrow-right"></u-icon>
					</u-cell>
				</u-cell-group>
				<mescroll-empty v-else></mescroll-empty>
			</view>
		</u-popup>

		<u-modal :show="data.modalShow" :title="data.modelTitle" :showCancelButton="true" @confirm="submitForm"
			@cancel="data.modalShow = false">
			<view class="slot-content">
				<u--form labelPosition="left" :model="data.form" ref="form1" label-width="80">
					<u-form-item :label="data.adjustType == 'sell_check' ? '检验人' : '反馈人'" prop="sex" borderBottom
						@click="data.userPickerShow = true;" v-if="data.modalType === 'add'">
						<u--input v-model="data.form.operatorName" disabled disabledColor="#ffffff" placeholder="请选择反馈人"
							border="none"></u--input>
						<template #right>
							<u-icon name="arrow-right"></u-icon>
						</template>
					</u-form-item>
					<u-form-item :label="data.adjustType == 'sell_check' ? '检查时间':'记录日期'" prop="operatorDate"
						borderBottom @click="data.dateShow = true;" v-if="data.modalType === 'add'">
						<u--input v-model="data.form.operatorDate" disabled disabledColor="#ffffff"
							placeholder="请选择记录日期" border="none"></u--input>
						<template #right>
							<u-icon name="arrow-right"></u-icon>
						</template>
					</u-form-item>
					<u-form-item label="处理工时" prop="attr3" borderBottom v-if="data.modalType === 'add'">
						<u--input v-model="data.form.attr3" placeholder="请输入处理工时" border="none"></u--input>
					</u-form-item>
					<u-form-item label="责任班组" prop="sex" borderBottom @click="data.groupPickerShow = true;"
						v-if="data.modalType === 'add' && (data.adjustType ==='rectification' || data.adjustType ==='sell_check') ">
						<u--input v-model="data.form.attr1" disabled disabledColor="#ffffff" placeholder="请选择责任班组"
							border="none"></u--input>
						<template #right>
							<u-icon name="arrow-right"></u-icon>
						</template>
					</u-form-item>
					<u-form-item :label="data.adjustType == 'sell_check' ? '检查项目' : '问题描述'" prop="adjustItem"
						borderBottom v-if="data.modalType === 'add'">
						<u--textarea v-model="data.form.adjustItem" placeholder="请输入问题描述" border="none"></u--textarea>
					</u-form-item>
					<u-form-item label="用户名称" prop="sex" borderBottom @click="data.userPickerShow = true;"
						v-if="data.modalType === 'check'">
						<u--input v-model="data.form.checkerName" disabled disabledColor="#ffffff" placeholder="请选择用户名称"
							border="none"></u--input>
						<template #right>
							<u-icon name="arrow-right"></u-icon>
						</template>
					</u-form-item>
					<u-form-item label="记录日期" prop="operatorDate" borderBottom @click="data.dateShow = true;"
						v-if="data.modalType === 'check'">
						<u--input v-model="data.form.checkerDate" disabled disabledColor="#ffffff" placeholder="请选择记录日期"
							border="none"></u--input>
						<template #right>
							<u-icon name="arrow-right"></u-icon>
						</template>
					</u-form-item>
					<u-form-item label="工艺判定" prop="attr1" borderBottom v-if="data.modalType === 'check'">
						<u--input v-model="data.form.attr1" placeholder="请输入工艺判定" border="none"></u--input>
					</u-form-item>
					<u-form-item label="品管判定" prop="attr2" borderBottom v-if="data.modalType === 'check'">
						<u--input v-model="data.form.attr2" placeholder="请输入品管判定" border="none"></u--input>
					</u-form-item>
					<u-form-item label="处理方案" prop="adjustResult" borderBottom v-if="data.modalType === 'deal'">
						<u--input v-model="data.form.adjustResult" placeholder="请输入处理方案" border="none"></u--input>
					</u-form-item>
				</u--form>
			</view>
		</u-modal>

		<u-modal :show="data.checkModalShow" title="提交" :showCancelButton="true" @confirm="submitCheckForm"
			@cancel="data.checkModalShow = false">
			<u--form labelPosition="left" :model="data.form" ref="form1" label-width="80">
				<u-form-item label="审核人" prop="sex" borderBottom @click="data.userPickerShow = true;">
					<u--input v-model="data.form.checkerName" disabled disabledColor="#ffffff" placeholder="请选择审核人"
						border="none"></u--input>
					<template #right>
						<u-icon name="arrow-right"></u-icon>
					</template>
				</u-form-item>
			</u--form>
		</u-modal>

		<u-picker :show="data.userPickerShow" keyName="nickName" :columns="data.userPickerColumns"
			@cancel="data.userPickerShow = false" @confirm="chooseUser"></u-picker>

		<u-picker :show="data.groupPickerShow" keyName="name" :columns="data.groupPickerColumns"
			@cancel="data.groupPickerShow = false" @confirm="chooseGroup"></u-picker>

		<u-datetime-picker :show="data.dateShow" v-model="data.form.time" mode="date" @cancel="data.dateShow = false"
			@confirm="chooseDate"></u-datetime-picker>
	</view>
</template>

<script lang="ts" setup>
	import { getAdjustItemList, itemFiledelete, adjusttypeitemSave, eqmbomlist, getUnitList, getAjusttypeList, getRoleUserList, shakeDowndelete, getGroupNoPage, updateStatus, adjusttypeitemSaveMemo } from '@/api/planList/planList.js'
	import { reactive, ref } from "vue";
	import { onShow, onLoad, onReachBottom, onPageScroll, onUnload } from "@dcloudio/uni-app";
	import useMescroll from "@/uni_modules/mescroll-uni/hooks/useMescroll.js";
	import dayjs from 'dayjs';
	import base from "@/common/baseUrl.js";
	import timelineItem from '@/components/chenbin-timeline/timelineItem.vue'
	const upOption = {
		auto: false,
		noMoreSize: 10, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
		textNoMore: '-- 没有更多啦 --', // 没有更多数据的提示文本
		empty: {
			tip: '~ 暂无数据 ~' // 提示
		}
	}
	const downOption = {
		auto: false,
	}

	const { mescrollInit, downCallback, getMescroll } = useMescroll(onPageScroll, onReachBottom)

	const base_url = base.baseUrl
	const data : any = reactive({
		list: [],
		isRefreshList: [],
		titleStyle: {
			color: '#fff',
			fontSize: '34rpx',
			fontWeight: '600'
		},
		loading: false,
		loadingText: '加载中',
		planEqmId: null,
		processId: null,
		noMore: false,
		listQuery: {
			planEqmId: null,
			typeName: null,
		},
		scrollTop: 0,
		pickerShow: false,
		pickerColumns: [],
		listIndex: null,
		title: '请选择登记表',
		adjustType: '',
		searchShow: false,
		typeList: [],
		shakeDownType: 'normal',
		// shakeDownType: 'special',
		modalShow: false,
		modalType: 'add',
		modelTitle: '新增调试记录',
		form: {
			time: Date.now()
		},
		userPickerShow: false,
		userPickerColumns: [],
		dateShow: false,
		role: '',
		checkModalShow: false,
		groupPickerShow: false,
		groupPickerColumns: [],
		planStatus: '',
		userInfo: {},
		modalTitle: "",
		boonListData: {}

	});
	onLoad((options) => {
		if (options.planEqmId) {
			data.planEqmId = options.planEqmId
			data.listQuery.planEqmId = data.planEqmId
		}
		if (options.planStatus) {
			data.planStatus = options.planStatus
		}

		data.role = uni.getStorageSync('role')

		data.userInfo = uni.getStorageSync('userInfo')
		getUnitList().then(res => {
			data.pickerColumns = [res.rows]
		})
		ajusttypeList()
		getGroupNoPage().then(res => {
			data.groupPickerColumns = [res.data]
		})
		getRoleUserList({ roleNames: '生产,调试,品管' }).then(res => {
			data.userPickerColumns = [res.rows]
		})
	});

	onShow(() => {

	})
	onUnload(() => {
		uni.$emit('refresh')
	})
	const upCallback = async (mescroll) => {
		try {

			const params = {
				current: mescroll.num,
				size: mescroll.size,
				planEqmId: data.listQuery.planEqmId,
				typeName: data.listQuery.typeName,
				keywords: data.listQuery.keywords,
			}
			const Boomparams = {
				current: mescroll.num,
				size: mescroll.size,
				// planEqmId:data.listQuery.planEqmId,
				materialName: data.listQuery.keywords,
			}
			let res = ref(null)
			if (data.listQuery.typeName == 'Bom') {
				res = await eqmbomlist(Boomparams);
			} else {
				res = await getAdjustItemList(params)
			}

			const curPageData = res.data.records || [] // 当前页数据
			if (mescroll.num == 1) data.list = []; // 第一页需手动制空列表
			data.list = data.list.concat(curPageData)
			data.list.map(item => {
				let keyfiles = []
				if (item.files && item.files.length) {
					item.files.map(i => {
						const keyfilesObj = {
							fileId: i.id,
							itemId: item.id,
							url: i.uri
						}
						keyfiles.push(keyfilesObj)
					})

				}
				item.keyfiles = keyfiles
				if (item.adjustResult != 0) {
					item.adjustResult = 2
				}
				item.isExpand = false
				item.isBtnShow = false
			})
			mescroll.endByPage(curPageData.length, res.data.total);


		} catch (e) {
			//TODO handle the exception
		}
	}
	const ajusttypeList = () => {
		if (data.role === '调试') {
			getAjusttypeList({ size: 999, current: 1, planEqmId: data.planEqmId }).then(res => {
				data.typeList = res.data.records
				data.searchShow = true;
				data.typeList.push(
					{
						adjustType: 'Bom',
						adjustName: '一机一Bom',
						id: 5,
					},
				)
			})
		} else {
			data.typeList = [
				{
					adjustType: 'adjust_abnormal',
					adjustName: '装配异常情况登记表',
					id: 1,
				},
				{
					adjustType: 'unqualified',
					adjustName: '制造过程不合格记录表',
					id: 2,
				},
				{
					adjustType: 'rectification',
					adjustName: '整改记录',
					id: 3,
				},
				{
					adjustType: 'sell_check',
					adjustName: '入库检',
					id: 4,
				},
				{
					adjustType: 'Bom',
					adjustName: '一机一Bom',
					id: 5,
				},
			]
			data.searchShow = true
		}
	}

	const qualified = (item, type) => {
		const obj = { ...item }
		obj.adjustResult = type;
		if (obj.adjustResult == 2 && !obj.adjustSuggest) {

			uni.showToast({
				title: '请填写整改意见！',
				icon: "none"
			})
			return;
		}
		if (obj.adjustResult == 0) {
			obj.status = '待整改'
		}
		adjusttypeitemSave(obj).then((res) => {
			if (res.status === 200) {
				// data.list = []
				// getData();
				uni.showToast({
					title: '操作成功',
					icon: "none"
				})
				getMescroll().resetUpScroll()
			}
		});
	}

	const change = (e, item) => {

		const obj = { ...item }

		if (obj.adjustResult == 2 && !obj.adjustSuggest) {

			uni.showToast({
				title: '请填写整改意见！',
				icon: "none"
			})
			return;
		}
		if (obj.adjustResult == 0) {
			obj.status = '待整改'
		}
		adjusttypeitemSave(obj).then((res) => {
			if (res.status === 200) {
				// data.list = []
				// getData();
				uni.showToast({
					title: '操作成功',
					icon: "none"
				})
				getMescroll().resetUpScroll()
			}
		});
	}
	const showBtn = (item) => {
		item.isBtnShow = true
	}

	const saveMemo = (item) => {
		adjusttypeitemSaveMemo(item).then((res) => {
			if (res.status === 200) {
				uni.showToast({
					title: '操作成功',
					icon: 'none'
				})
				item.isBtnShow = false
			}
		});
	}
	const openPicker = (item, index) => {
		data.listIndex = index
		data.pickerShow = true
	}
	const chooseUnit = (item) => {
		data.list[data.listIndex].unit = item.value[0].measureCode
		if (data.list[data.listIndex].adjustResult) {
			adjusttypeitemSave(data.list[data.listIndex]).then(res => {
				uni.showToast({
					title: '操作成功',
					icon: 'none'
				})
				// getData()
				data.pickerShow = false
			})
		}
	}
	const saveResult = (item) => {
		adjusttypeitemSave(item).then(res => {
			// getData()
			uni.showToast({
				title: '操作成功',
				icon: 'none'
			})
			data.pickerShow = false
		})
	}
	const filterUnit = (val : any) => {
		const index = data.pickerColumns[0].findIndex((item) => item.measureCode === val);
		return index !== -1 ? data.pickerColumns[0][index].measureName : "";
	}
	const afterRead = (e) => {
		const itemId = e.name;
		let files = e.file;
		if (files.length) {
			files.map(async (item) => {
				uni.uploadFile({
					url: base_url + '/proplan/plan/adjusttype/item/fileupload', //接口
					filePath: item.thumb,
					name: 'file',
					header: {
						Authorization: uni.getStorageSync("access_token"),
					},
					file: item,
					formData: {
						itemId
					},
					success: async res => {
						let resData = JSON.parse(res.data);
						if (resData.status == 200 && resData.data.uri) {
							data.list.map((i) => {
								if (i.id == itemId) {
									i.keyfiles.push({
										fileId: resData.data.id,
										itemId: itemId,
										url: resData.data.uri
									})
								}
							})
						}
					}
				})
			})
		}
	}
	const deletePic = (e, item) => {
		if (data.adjustType === 'offline_inspection' || data.adjustType === 'handover' || data.adjustType === 'adjust_abnormal') return
		if (data.adjustType === 'unqualified' && item.status !== '草稿') return
		uni.showModal({
			title: '提示',
			content: '确认要删除该条数据吗？',
			success: function (res) {
				if (res.confirm) {
					const index = data.list.findIndex(item => item.id == e.file.itemId)
					itemFiledelete(e.file.itemId, e.file.fileId).then(res => {
						data.list[index].keyfiles.splice(e.index, 1)
					})
				} else if (res.cancel) {
					console.log('用户点击取消');
				}
			}
		});

	}

	const reSearch = () => {
		getMescroll().resetUpScroll()
	}

	const chooseType = (item) => {
		data.listQuery.keywords = ''
		data.listQuery.typeName = item.adjustType
		data.list = []
		data.title = item.adjustName
		data.adjustType = item.adjustType
		if (item.adjustType === "unqualified" || item.adjustType === "Bom" || item.adjustType === "adjust_abnormal" || item.adjustType === "rectification" || item.adjustType === "sell_check") {
			data.shakeDownType = "special";
		} else {
			data.shakeDownType = "normal";
		}

		data.searchShow = false;
		getMescroll().resetUpScroll()

	}

	const getModalTitle = (type : string) => {
		if (type = 'add' && data.adjustType == 'rectification') {
			return '新增整改记录'
		} else if (type = 'add' && data.adjustType == 'sell_check') {
			return '新增检查记录'
		} else if (type = 'check') {
			return '新增工艺判定'
		} else if (type = 'deal') {
			return '新增处理方案'
		}
	}
	const openModal = (type, item) => {
		data.modalType = type
		data.modelTitle = getModalTitle(type);
		data.modalShow = true
		if (type === 'add') {

			data.form = {
				operator: data.userInfo.userId,
				operatorName: data.userInfo.nickName,
				operatorDate: dayjs().format('YYYY-MM-DD'),
				operatorTime: dayjs().unix()
			}
		} else {
			data.form = { ...item }
		}
	}
	const openCheckModal = (row) => {
		data.modalType = 'check'
		data.form = { ...row }
		data.checkModalShow = true
	}
	const closeItem = (item) => {
		item.status = '已关闭'
		adjusttypeitemSave(item).then(res => {
			if (res.status === 200) {
				uni.showToast({
					title: '操作成功',
					icon: 'none'
				})
				data.modalShow = false
				getMescroll().resetUpScroll()
			}
		})
	}
	const chooseGroup = (e) => {
		data.form.attr1 = e.value[0].name
		data.groupPickerShow = false
	}
	const chooseUser = (e) => {
		if (data.modalType === 'add') {
			data.form.operator = e.value[0].userId
			data.form.operatorName = e.value[0].nickName
		} else {
			data.form.checker = e.value[0].userId
			data.form.checkerName = e.value[0].nickName
		}
		data.userPickerShow = false
	}
	const chooseDate = (e) => {
		data.form.operatorDate = dayjs(e.value).format('YYYY-MM-DD')
		data.form.operatorTime = e.value / 1000
		if (data.modalType === 'add') {
			data.form.operatorDate = dayjs(e.value).format('YYYY-MM-DD')
			data.form.operatorTime = e.value / 1000
		} else {
			data.form.checkerDate = dayjs(e.value).format('YYYY-MM-DD')
			data.form.checkerTime = e.value / 1000
		}
		data.dateShow = false
	}
	const submitForm = () => {
		switch (data.modalType) {
			case 'add':
				const { operatorDate, time, ...obj } = data.form
				obj.planEqmId = data.planEqmId
				if (data.adjustType === 'rectification') {
					obj.typeName = data.adjustType
					obj.status = '待整改'
				} else if (data.adjustType === 'sell_check') {
					obj.typeName = data.adjustType
					obj.status = '待检验'
				} else {
					obj.typeId = data.listQuery.typeId
					obj.status = '草稿'
				}
				adjusttypeitemSave(obj).then(res => {
					if (res.status === 200) {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})
						data.modalShow = false
						getMescroll().resetUpScroll()
					}
				})
				return
			case 'check':
				if (data.adjustType === 'sell_check') {
					data.form.status = '待整改'
				} else {
					data.form.status = '已审核待处理'
				}
				adjusttypeitemSave(data.form).then(res => {
					if (res.status === 200) {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})
						data.modalShow = false
						getMescroll().resetUpScroll()
					}
				})
				return
			case 'deal':
				data.form.status = '已审核待处理'
				adjusttypeitemSave(data.form).then(res => {
					if (res.status === 200) {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})
						data.modalShow = false
						getMescroll().resetUpScroll()
					}
				})
				return
		}
	}
	const submitCheckForm = () => {
		const { operatorDate, time, ...obj } = data.form
		obj.planEqmId = data.listQuery.planEqmId
		obj.typeName = 'unqualified'
		obj.status = '审核中'
		adjusttypeitemSave(obj).then(res => {
			if (res.status === 200) {
				uni.showToast({
					title: '操作成功',
					icon: 'none'
				})
				data.checkModalShow = false
				getMescroll().resetUpScroll()
			}
		})
	}
	const formatDate = (val) => {
		return dayjs(val * 1000).format('YYYY-MM-DD HH:mm:ss');
	}
	const delData = async (item, index) => {
		uni.showModal({
			title: '提示',
			content: '确认删除吗？',
			success: async function (sres) {
				if (sres.confirm) {
					uni.showToast({
						title: '删除成功',
						icon: 'none'
					})
					const res = await shakeDowndelete(item.id)
					getMescroll().resetUpScroll()
				}
			}
		});
	}
	const endCheck = (item) => {
		item.status = '待验收'
		adjusttypeitemSave(item).then(res => {
			if (res.status === 200) {
				uni.showToast({
					title: '操作成功',
					icon: 'none'
				})
				data.checkModalShow = false
				getMescroll().resetUpScroll()
			}
		})
	}
	const updatestatus = (status, statusName, id) => {
		const obj = { status, statusName, id }
		uni.showModal({
			title: '提示',
			content: `确定要提交${statusName}吗？`,
			success: function (res) {
				if (res.confirm) {
					updateStatus(obj).then(res => {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})
					})
				}
			}
		});

	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f5f5;
	}

	::v-deep .u-steps--column {
		padding-top: 20rpx;

		.u-steps-item__content {
			.u-text__value {
				font-size: 30rpx !important;

			}

			.u-text__value--tips {
				font-size: 28rpx !important;
			}
		}
	}

	.qualifiedOrunQualified {
		display: flex;
		justify-content: space-between;

		.qualifiedOr {
			width: 50%;
		}
	}

	.navTitle {
		color: #fff;
		font-size: 34rpx;
		font-weight: bold;
	}

	.searchBox {
		padding: 30rpx 20rpx;
		background-color: #fff;
		box-shadow: 0 0 10rpx 0 #eeeeee;
	}


	.shake_item {

		background: #fff;
		margin-top: 20rpx;
		border-radius: 20rpx;
		box-shadow: 0 0 10rpx 0 #bbbbbb;
		overflow: hidden;
		margin-bottom: 60rpx;

		.shake_top {
			border-radius: 20rpx 20rpx 0 0;
			background: #0081fe;
			padding: 24rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

		}

		.shake_bottom {
			background-color: #fff;
			padding: 24rpx;

			// border-left:  2px solid #000;
			// border-right:  2px solid #000;
			.shake_bottom_item {
				border-bottom: 1px solid #eeeeee;
				padding: 20rpx 0;
				font-size: 16px;
				display: flex;
				justify-content: space-between;
				align-items: flex-start;

				.shake_bottom_l {
					width: 30%;
				}

				.shake_bottom_r {
					flex: 1;
					color: #3975c6;
				}

			}
		}

		.lookMore {
			padding: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			padding-bottom: 40rpx;

			.more {
				margin-right: 20rpx;
				font-size: 28rpx;
				color: #999999;
			}
		}
	}

	.special_shake {
		background: #fff;
		margin-bottom: 40rpx;
		padding: 20rpx;
		border-radius: 10rpx;
		box-shadow: 0 0 10rpx 0 #bbbbbb;

		.special_shake_item_top {
			display: flex;
			justify-content: space-between;
			padding: 20rpx 0;
		}

		.special_shake_item {
			border-bottom: 1px solid #eeeeee;
			padding: 20rpx 0;
			display: flex;
			justify-content: space-between;
			align-items: flex-start;

			&.start {
				justify-content: flex-start;
			}

			.special_shake_item_l {
				width: 30%;
			}

			.special_shake_item_r {
				flex: 1;
				color: #3975c6;

			}

			.attr {
				display: flex;
				justify-content: space-between;

				.u-button {
					width: 30px !important;
				}
			}
		}
	}

	.bottom_btn {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		display: flex;
		justify-content: flex-end;
		padding: 12px;
		padding-bottom: 24px;
		background-color: #fff;
		padding-right: 80%;
	}

	.bottom_img {
		position: fixed;
		bottom: 300rpx;
		right: 20rpx;
		width: 120rpx;
		height: 120rpx;
	}

	.type_item {
		padding: 12px 12px;
		border: 1px solid #606266;
		border-radius: 6px;
		color: #0E3A5E;
		display: flex;
		justify-content: space-between;
		margin-bottom: 24rpx;
	}

	::v-deep .projectListPup {
		.u-popup__content__close--top-right {
			top: 120rpx !important;
		}

		.u-popup__content {
			width: 80vw;

			.u-popup__content__close {
				top: 70rpx !important;
			}

			.uicon-close {
				color: #0E3A5E !important;
			}
		}
	}

	.projectList {
		padding: 70rpx 20rpx;
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow-y: auto;

		.top {
			display: flex;
			align-items: center;
			margin-bottom: 46rpx;

			.u-text__value--primary {
				font-size: 34rpx !important;
				margin-left: 23rpx;
				font-weight: bold !important;
				color: #0E3A5E !important;
			}
		}

		.searchPro {
			margin-bottom: 40rpx;
		}

		.pcontend {
			overflow-y: auto;
		}

		.u-cell {
			border: 1px solid #DCDCDC;
			border-radius: 12rpx;
			margin-bottom: 20rpx;

			&.activePro {
				border-color: #0E3A5E;

				.u-cell__title-text {
					color: #0E3A5E;
				}

				.uicon-arrow-right {
					color: #0E3A5E !important;
				}
			}

			.u-cell__title-text {
				color: #0A1629;
				font-size: 32rpx;
			}
		}

	}

	::v-deep .u-popup__content {
		min-height: 128px;
	}

	::v-deep .u-read-more__toggle__text {
		padding-top: 20rpx;
	}

	// ::v-deep .u-read-more__content{
	// 	height: auto !important;
	// }
</style>